package com.bocai.freeman.utils;

import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import com.bocai.freeman.R;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;


public class ToolbarHelper {
    public static void setup(RxAppCompatActivity activity, String title, int resId, View.OnClickListener onClickListener) {
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        TextView tvTitle = (TextView) toolbar.findViewById(R.id.title);
        tvTitle.setText(title);
        activity.setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
    }

    public static void setup(RxAppCompatActivity activity) {
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        activity.setSupportActionBar(toolbar);
    }

    public static void setup(RxAppCompatActivity activity, String title) {
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        TextView tvTitle = (TextView) toolbar.findViewById(R.id.title);
        tvTitle.setText(title);
        activity.setSupportActionBar(toolbar);
    }

    public static void setup(RxAppCompatActivity activity, String title, String leftName, int resId, View.OnClickListener onClickListener) {
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        TextView tvTitle = (TextView) toolbar.findViewById(R.id.title);
        tvTitle.setText(title);
        activity.setSupportActionBar(toolbar);
        toolbar.setNavigationContentDescription(leftName);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
    }


    public static void setup(RxAppCompatActivity activity, String title, int resId, int resIdMenu
            , View.OnClickListener onClickListener, Toolbar.OnMenuItemClickListener onMenuItemClickListener) {
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        TextView tvTitle = (TextView) toolbar.findViewById(R.id.title);
        tvTitle.setText(title);
        toolbar.inflateMenu(resIdMenu);
        toolbar.setOnMenuItemClickListener(onMenuItemClickListener);
        toolbar.setNavigationIcon(resId);
        toolbar.setNavigationOnClickListener(onClickListener);
    }

    public static void setup(RxAppCompatActivity activity,int title,int icon){
        Toolbar toolbar = (Toolbar) activity.findViewById(R.id.toolbar);
        toolbar.setTitle("");
        TextView tvTitle = (TextView) toolbar.findViewById(R.id.title);
        tvTitle.setText(title);
        activity.setSupportActionBar(toolbar);
        toolbar.setNavigationIcon(icon);
        toolbar.setNavigationOnClickListener(v -> activity.onBackPressed());
    }

}
